package org.geektimes.projects.user.web.controller;

import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.repository.HomeworkUserRepository;
import org.geektimes.projects.user.repository.UserRepository;
import org.geektimes.web.mvc.controller.PageController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Path;
import java.sql.SQLException;

/**
 * @author :   chuan
 * @date :   2021/0
 */
public class RegistryPageController implements PageController {

    private final UserRepository userRepository;
    public RegistryPageController() {
        this.userRepository = new HomeworkUserRepository();
    }

    @Path("/registry-form")
    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) {
        return "registry-form.jsp";
    }

    @Path("/doFormRegistry")
    public String registryForm(User user, Integer age, HttpServletRequest request, HttpServletResponse response) throws SQLException {

        userRepository.save(user);

        return "registry-success.jsp";
    }

    @Path("/registry-ajax")
    public String registryAjax() {
        return "registry-ajax.jsp";
    }

    @Path("/registry-success")
    public String registrySuccess() {
        return "registry-success.jsp";
    }
}
